<%@ page language="java"  import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.hk.entity.User,com.hk.dao.*" %>
<%  
	request.setCharacterEncoding("utf-8");   //处理请求乱码
	response.setCharacterEncoding("utf-8");
	
	String name = request.getParameter("uname"); //接收客户端传来的参数
	String pwd = request.getParameter("pwd");
	
	UserDAO ud = new UserDAO();
	User u= ud.login(name,pwd);
	
	int n = 0;//登入用户点击的次数
	List<User> loginedUsers = null;
	loginedUsers = (List<User>) application.getAttribute("ALL_LOGINED_USERS");//从application中获取所有登入用户

	if(u!=null){
		if(loginedUsers==null){
			loginedUsers = new ArrayList<User>();
			loginedUsers.add(u);
		}else{
			loginedUsers.add(u);
		}
		application.setAttribute("ALL_LOGINED_USERS", loginedUsers);//把登入成功的用户放在application中
		session.setAttribute("LoginedUser", u);//登入成功,将成功的用户放到session里面
		//response.sendRedirect("index.html");
		session.setAttribute("msg", null);//重定向
		request.getRequestDispatcher("index.jsp").forward(request, response);//请求转发
	}
	else{
		//response.sendRedirect("login.jsp");
		request.getRequestDispatcher("login.jsp").forward(request, response);
		System.out.println("登入失败");
		session.setAttribute("msg", "用户名或密码错误");//登入不成功,将不成功的信息加入到session
	}
%>